﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PhoobearLibs.Resource.Resx
{
    /// <summary>
    /// 리소스 파일을 한타입에서 다른 타입으로 변환합니다.
    /// </summary>
    /// <typeparam name="TSourceValue">소스 타입</typeparam>
    /// <typeparam name="TTargetValue">타겟 타입</typeparam>
    public static class ResourceTypeConverter<TSourceValue, TTargetValue>
    {
        /// <summary>
        /// 변환
        /// </summary>
        /// <param name="sourceFile">원본파일</param>
        /// <param name="targetFile">타겟파일</param>
        /// <param name="valueTypeConverter">타입변환방식</param>
        /// <returns>변환성공여부</returns>
        public static Resource<TTargetValue> Convert(Resource<TSourceValue> source, Resource<TTargetValue> target, Func<TSourceValue, TTargetValue> valueTypeConverter)
        {
            foreach (var item in source.Data)
            {
                TTargetValue newValue = valueTypeConverter(item.Value);
                KeyValuePair<string, TTargetValue> newItem = new KeyValuePair<string, TTargetValue>(item.Key, newValue);
                target |= newItem;
            }

            return target;
        }
    }
}
